


# Check Pytorch installation
import torch, torchvision
print(torch.__version__, torch.cuda.is_available())

# Check MMDetection installation
import mmdet
print(mmdet.__version__)

# Check mmcv installation
from mmcv.ops import get_compiling_cuda_version, get_compiler_version
print(get_compiling_cuda_version())
print(get_compiler_version())




# Let's take a look at the dataset image
import mmcv
import matplotlib.pyplot as plt

img = mmcv.imread('data/kitti_tiny/training/image_2/000000.jpeg')
plt.figure(figsize=(15, 10))
plt.imshow(mmcv.bgr2rgb(img))
plt.show()





from mmdet.apis import init_detector, inference_detector, show_result_pyplot

config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# 从 model zoo 下载 checkpoint 并放在 `checkpoints/` 文件下
# 网址为: http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'

device = 'cuda:0'

# 初始化检测器
model = init_detector(config_file, checkpoint_file, device=device)

# 推理 演示图像
imgpath = 'demo/demo.jpg'
result=inference_detector(model, 'demo/demo.jpg')

print(result)

# Let's plot the result 显示结果
show_result_pyplot(model, imgpath, result, score_thr=0.3)

# 测试显示
# python demo/image_demo.py demo/demo.jpg configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py  checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth

# 打印 cfg 文件 完整的 配置 信息 -- 并保存 到txt中
# python tools/misc/print_config.py configs/faster_rcnn/faster_rcnn_r50_caffe_c4_1x_coco.py > cfg.txt





